package com.panfeng.xcloud.boss.provider.member.web.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.panfeng.xcloud.boss.provider.member.dto.request.*;
import com.panfeng.xcloud.boss.provider.member.dto.response.GetExchangeSupportCoinsRespDTO;
import com.panfeng.xcloud.boss.provider.member.service.IExchangeBindingHuobiService;
import com.panfeng.xcloud.boss.provider.member.web.vo.request.*;
import com.panfeng.xcloud.boss.provider.member.web.vo.response.GetApiInfoRespVO;
import com.panfeng.xcloud.boss.provider.member.web.vo.response.GetExchangeSupportCoinsRespVO;
import com.panfeng.xcloud.boss.provider.member.web.vo.response.GetSupportCoinsRespVO;
import com.panfeng.xcloud.common.core.utils.ConvertUtils;
import com.panfeng.xcloud.common.core.web.vo.ResponseVO;
import com.panfeng.xcloud.common.security.annotation.MethodValidate;
import com.panfeng.xcloud.common.security.annotation.NotNeedAccess;
import com.panfeng.xcloud.common.security.web.support.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;


/**
 * 用户huobi交易所授权
 *
 * @author 肖博
 * @version 1.0
 * @since 2019-11-15
 */
@RestController
@RequestMapping("user/exchange/huobi")
@Api(tags = {"用户绑定Huobi交易所模块"})
@Slf4j
public class UserExchangeBindingHuobiController extends BaseController {

    @Autowired
    private IExchangeBindingHuobiService exchangeBindingService;


    @MethodValidate
    @PostMapping(value = "/huobiVerify")
    @ApiOperation(value = "账户实盘绑定huobi校验(肖博)", httpMethod = "POST",notes = "绑定或绑定和重新绑定同一个接口")
    public ResponseVO<Boolean> huobiVefify(@Validated @RequestBody HuobiVerifyReqVO reqVO, BindingResult bindingResult) {
        log.info(">>>> 当前huobiVefify请求参数：{} <<<",(null != reqVO ? JSONObject.toJSONString(reqVO):""));
        //获取当前用户的userId
        String currentUserId = getCurrentUserId();
//        String currentUserId = "b46116";
        HuobiVerifyReqDTO huobiBindingReqDTO = ConvertUtils.convert(reqVO, HuobiVerifyReqDTO.class);
        huobiBindingReqDTO.setUserId(currentUserId);
        Boolean result = exchangeBindingService.huobiVerify(huobiBindingReqDTO);
        log.info(">>>> 当前huobiVefify响应报文pageDTO：{} <<<",(result));
        return result ?ResponseVO.success() : ResponseVO.error();
    }

    @MethodValidate
    @PostMapping(value = "/huobiBinding")
    @ApiOperation(value = "账户实盘绑定huobi(肖博)", httpMethod = "POST",notes = "绑定前需要先调用校验的接口,绑定或绑定和重新绑定同一个接口")
    public ResponseVO<Boolean> huobiBinding(@Validated @RequestBody HuobiBindingReqVO reqVO, BindingResult bindingResult) {
        log.info(">>>> 当前huobiBinding请求参数：{} <<<",(null != reqVO ? JSONObject.toJSONString(reqVO):""));
        //获取当前用户的userId
        String currentUserId = getCurrentUserId();
        HuobiBindingReqDTO huobiBindingReqDTO = ConvertUtils.convert(reqVO, HuobiBindingReqDTO.class);
        huobiBindingReqDTO.setUserId(currentUserId);
        Boolean result = exchangeBindingService.huobiBinding(huobiBindingReqDTO);
        log.info(">>>> 当前huobiBinding响应报文pageDTO：{} <<<",(result));
        return result ?ResponseVO.success() : ResponseVO.error();
    }

    @MethodValidate
    @PostMapping(value = "/reHuobiBinding")
    @ApiOperation(value = "修改huobi绑定接口(肖博)", httpMethod = "POST",notes = "修改huobi绑定接口")
    public ResponseVO<Boolean> reHuobiBinding(@Validated @RequestBody ReHuobiBindingReqVO reqVO, BindingResult bindingResult) {
        log.info(">>>> 当前reHuobiBinding请求参数：{} <<<",(null != reqVO ? JSONObject.toJSONString(reqVO):""));
        //获取当前用户的userId
        String currentUserId = getCurrentUserId();
//        String currentUserId = "b46116";
        HuobiBindingReqDTO huobiBindingReqDTO = ConvertUtils.convert(reqVO, HuobiBindingReqDTO.class);
        huobiBindingReqDTO.setUserId(currentUserId);
        Boolean result = exchangeBindingService.reHuobiBinding(huobiBindingReqDTO);
        log.info(">>>> 当前reHuobiBinding响应报文pageDTO：{} <<<",(result));
        return result ?ResponseVO.success() : ResponseVO.error();
    }

    @MethodValidate
    @PostMapping(value = "/huobiUnbind")
    @ApiOperation(value = "huobi解绑(肖博)", httpMethod = "POST",notes = "调用该接口前应先进行极验和短信验证")
    public ResponseVO<Boolean> huobiUnbind(@Validated @RequestBody HuobiUnbindReqVO reqVO, BindingResult bindingResult) {
        log.info(">>>> 当前huobiUnbind请求参数：{} <<<",(null != reqVO ? JSONObject.toJSONString(reqVO):""));
        //获取当前用户的userId
        String currentUserId = getCurrentUserId();
//        String currentUserId = "b46116";
        HuobiUnbindReqDTO huobiBindingReqDTO = ConvertUtils.convert(reqVO, HuobiUnbindReqDTO.class);
        huobiBindingReqDTO.setUserId(currentUserId);
        Boolean result = exchangeBindingService.huobiUnbind(huobiBindingReqDTO);
        log.info(">>>> 当前huobiUnbind响应报文pageDTO：{} <<<",(result));
        return result ?ResponseVO.success() : ResponseVO.error();
    }

    @ApiIgnore
    @NotNeedAccess
    @MethodValidate
    @PostMapping(value = "/updateSupportCoins")
    @ApiOperation(value = "修改当前支持币种(肖博)", httpMethod = "POST",notes = "修改当前支持币种")
    public ResponseVO<Boolean> updateSupportCoins(@Validated @RequestBody UpdateSupportCoinsReqVO reqVO, BindingResult bindingResult) {
        log.info(">>>> 当前updateSupportCoins请求参数：{} <<<",(null != reqVO ? JSONObject.toJSONString(reqVO):""));
        //获取当前用户的userId
        String currentUserId = getCurrentUserId();
//        String currentUserId = "h513";
        UpdateSupportCoinsReqDTO huobiBindingReqDTO = ConvertUtils.convert(reqVO, UpdateSupportCoinsReqDTO.class);
        huobiBindingReqDTO.setUserId(currentUserId);
        Boolean result = exchangeBindingService.updateSupportCoins(huobiBindingReqDTO);
        log.info(">>>> 当前updateSupportCoins响应报文pageDTO：{} <<<",(result));
        return result ?ResponseVO.success() : ResponseVO.error();
    }

    @ApiIgnore
    @NotNeedAccess
    @MethodValidate
    @PostMapping(value = "/getSupportCoins")
    @ApiOperation(value = "获取当前支持币种(肖博)", httpMethod = "POST",notes = "获取当前支持币种")
    public ResponseVO<GetSupportCoinsRespVO> getSupportCoins(@Validated @RequestBody GetSupportCoinsReqVO reqVO, BindingResult bindingResult) {
        log.info(">>>> 当前getSupportCoins请求参数：{} <<<",(null != reqVO ? JSONObject.toJSONString(reqVO):""));
//        获取当前用户的userId
        String currentUserId = getCurrentUserId();
//        String currentUserId = "h513";
        GetSupportCoinsReqDTO huobiBindingReqDTO = ConvertUtils.convert(reqVO, GetSupportCoinsReqDTO.class);
        huobiBindingReqDTO.setUserId(currentUserId);
        GetSupportCoinsRespVO supportCoins = exchangeBindingService.getSupportCoins(huobiBindingReqDTO);
        log.info(">>>> 当前getSupportCoins响应报文pageDTO：{} <<<", JSON.toJSONString(supportCoins));
        return ResponseVO.with(supportCoins);
    }

    @NotNeedAccess
    @MethodValidate
    @PostMapping(value = "/getApiInfo")
    @ApiOperation(value = "获取api信息(肖博)", httpMethod = "POST",notes = "api信息")
    public ResponseVO<GetApiInfoRespVO> getApiInfo(@Validated @RequestBody GetApiInfoReqVO reqVO, BindingResult bindingResult) {
        log.info(">>>> 当前getApiInfo请求参数：{} <<<",(null != reqVO ? JSONObject.toJSONString(reqVO):""));
        //获取当前用户的userId
        String currentUserId = getCurrentUserId();
//        String currentUserId = "b46108";
        GetApiInfoReqDTO huobiBindingReqDTO = ConvertUtils.convert(reqVO, GetApiInfoReqDTO.class);
        huobiBindingReqDTO.setUserId(currentUserId);
        GetApiInfoRespVO apiInfo = exchangeBindingService.getApiInfo(huobiBindingReqDTO);
        log.info(">>>> 当前getApiInfo响应报文pageDTO：{} <<<",(JSON.toJSONString(apiInfo)));
        return ResponseVO.with(apiInfo);
    }

    @ApiIgnore
    @NotNeedAccess
    @MethodValidate
    @PostMapping(value = "/getExchangeSupportCoins")
    @ApiOperation(value = "获取交易所支持币种信息(肖博)", httpMethod = "POST",notes = "传入accountId则会判断该用户是否支持币种")
    public ResponseVO<List<GetExchangeSupportCoinsRespVO>> getExchangeSupportCoins(@Validated @RequestBody GetExchangeSupportCoinsReqVO reqVO, BindingResult bindingResult) {
        log.info(">>>> 当前getExchangeSupportCoins请求参数：{} <<<",(null != reqVO ? JSONObject.toJSONString(reqVO):""));
        GetExchangeSupportCoinsReqDTO huobiBindingReqDTO = ConvertUtils.convert(reqVO, GetExchangeSupportCoinsReqDTO.class);
        List<GetExchangeSupportCoinsRespDTO> respDTOS = exchangeBindingService.getExchangeSupportCoins(huobiBindingReqDTO);
        List<GetExchangeSupportCoinsRespVO> convert = ConvertUtils.convert(respDTOS, GetExchangeSupportCoinsRespVO.class);
        log.info(">>>> 当前getExchangeSupportCoins响应报文pageDTO：{} <<<",(JSON.toJSONString(convert)));
        return ResponseVO.with(convert);
    }


}
